package com.boot.longAdder;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

public class Demo {

    public volatile int i = 0;

    public AtomicInteger atomicInteger = new AtomicInteger();

    public LongAdder longAdder = new LongAdder();

    LongAccumulator longAccumulator = new LongAccumulator((x, y) -> x+y,0);

    public synchronized void syc_add(){
        i++;
    }

    public void syc_in_add(){
        synchronized (this){
            i++;
        }
    }

    public void atomic (){
        atomicInteger.incrementAndGet();
    }

    public void add(){
        longAdder.increment();
    }

    public void add_LongAccumulator() {
        longAccumulator.accumulate(1);
    }
}
